<?php
ob_start();

include_once 'Core/Config.php';
include_once 'Controller/ControladorFather.php';
include_once 'Model/ModelFather.php';
include_once 'Model/Publicacao.php';
include_once 'Model/Categoria.php';
include_once 'Model/Autor.php';
include_once 'Model/Usuario.php';

date_default_timezone_set('America/Campo_Grande');
$publicacao = new Publicacao(host, dbname, port, user, pass);
$result = $publicacao->find(array('order' => array('nome')));
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="index.css" />

        <!-- tablesorter -->
        <script language="JavaScript" src="js/jquery-1.7.2.js"></script>
        <script language="JavaScript" src="js/jquery.columnfilters.js"></script>
        <script language="JavaScript" src="js/jquery.tablesorter.min.js"></script>
        <link rel="stylesheet" type="text/css" href="css/style.css">

        <!-- jquery for equal height elements -->
        <script type="text/javascript" src="js/formee.js"></script>
        <script type="text/javascript" src="js/jquery.click-calendario-1.0.js"></script>
        <script src="js/jQuery_vForms.js" type="text/javascript"></script>

        <!-- css for structure -->
        <link rel="stylesheet" href="css/formee-structure.css" type="text/css" media="screen" />

        <!-- css for style -->
        <link rel="stylesheet" href="css/formee-style.css" type="text/css" media="screen" />

        <link href="css/jquery.click-calendario-1.0.css" rel="stylesheet" type="text/css"/>
        <title>Biblioteca LATEC</title>
    </head>

    <body>

        <div id="wrap">
            <div id="header" >
                <div id="logo" type="width: auto; align: left">
                    <h1>Biblioteca LATEC</h1>
                </div>
                <div id="menu">
                    <ul>
                        <li><a a href="login.php">Logar - se</a></li>
                    </ul>
                </div>
            </div>
            <div class="clear"></div>
            <div id="content">

                <table id="tabela" cellspacing="0" cellpadding="0" class="tablesorter" type="width: auto">
                    <thead>
                        <tr>
                            <th>
                                Nome
                            </th>
                            <th>
                                Assunto
                            </th>
                            <th>
                                Categoria
                            </th>
                            <th>
                                Edição
                            </th>
                            <th>
                                Orientador
                            </th>
                            <th>
                                Autor
                            </th>
                            <th>
                                Data
                            </th>
                            <th>
                                Arquivo
                            </th>
                        </tr>
                    </thead>

                    <tfoot></tfoot>

                    <tbody>

                        <?php
                        $i = 0;
                        foreach ($result as $publicacao):
                            $i++
                            ?>
                            <tr <?php echo ($i % 2 == 0) ? 'class="gray"' : "" ?>>
                                <td><?php echo $publicacao['Publicacao']['nome'] ?></td>
                                <td><?php echo $publicacao['Publicacao']['assunto'] ?></td>
                                <td><?php echo $publicacao['Categoria']['name'] ?></td>
                                <td><?php echo $publicacao['Publicacao']['edicao'] ?></td>
                                <td><?php echo $publicacao['Publicacao']['orientador'] ?></td>
                                <td><?php echo $publicacao['Autor']['name'] ?></td>
                                <td><?php echo date('d M y', strtotime($publicacao['Publicacao']['datapublicacao'])) ?></td>
                                <td><a href="File/<?php echo $publicacao['Publicacao']['file'] ?>">Baixar</a></td>
                            </tr>
                            <?php
                        endforeach;
                        ?>
                    </tbody>
                </table> 
                <script>
                    $(document).ready(function() {
                        $('table#tabela').columnFilters({alternateRowClassNames:['rowa','rowb'],excludeColumns:[7]});
                        $("#tabela").tablesorter( {sortList: [[0,0], [0,0]]} ); 
                    });
                </script>

            </div>
        </div>

    </body>
</html>
